package com.siwei.mes.entity.experiment.concreteAdmixture;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import com.siwei.mes.entity.experiment.slag.SlagSsl;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 外加剂-含固量
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class ConcreteAdmixtureHgl {
    @ApiModelProperty(value = "平均含固量")//1
    private String pjhgl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "生产厂家控制值1")
    private String sccjkzz1 = "";
    @ApiModelProperty(value = "生产厂家控制值2")
    private String sccjkzz2 = "";
    @ApiModelProperty(value = "单项结论")
    private String dxjl = "";
    @ApiModelProperty(value = "含固量1信息")
    private ConcreteAdmixtureHgl.SyInfo sy1Info = new ConcreteAdmixtureHgl.SyInfo();
    @ApiModelProperty(value = "含固量2信息")
    private ConcreteAdmixtureHgl.SyInfo sy2Info = new ConcreteAdmixtureHgl.SyInfo();

    @Data
    @Accessors(chain = true)
    @ApiModel("含固量信息")
    public static class SyInfo {
        @ApiModelProperty(value = "称量瓶")
        private String clp = "";
        @ApiModelProperty(value = "试样质量")
        private String syzl = "";
        @ApiModelProperty(value = "烘干后质量")
        private String hghzl = "";
        @ApiModelProperty(value = "含固量")
        private String hgl = "";

    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        ConcreteAdmixtureHgl entity = new ConcreteAdmixtureHgl();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, ConcreteAdmixtureHgl.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, ConcreteAdmixtureHgl.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        ConcreteAdmixtureHgl entity = JsonUtils.getObject(objJson, ConcreteAdmixtureHgl.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjhgl()) || "null".equals(entity.getPjhgl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }

    public static void setValue(ConcreteAdmixtureHgl entity, Map<String, Object> data) {
        if (data.get("Conclusion") != null) {
            entity.setDxjl(data.get("Conclusion").toString());
        }
        if (data.get("AVGHGL") != null) {
            entity.setPjhgl(data.get("AVGHGL").toString());
        }
        if (data.get("SUBMITCSKZZ") != null) {
            entity.setSccjkzz1(data.get("SUBMITCSKZZ").toString());
        }
        if (data.get("SUBMITCSKZZCOPY") != null) {
            entity.setSccjkzz2(data.get("SUBMITCSKZZCOPY").toString());
        }

        // 修改第一个SyInfo
        ConcreteAdmixtureHgl.SyInfo sy1Info = entity.getSy1Info();
        if (sy1Info == null) {
            sy1Info = new ConcreteAdmixtureHgl.SyInfo();
            entity.setSy1Info(sy1Info);
        }
        if (data.get("S1P1") != null) {
            sy1Info.setClp(data.get("S1P1").toString());
        }
        if (data.get("S1HGL") != null) {
            sy1Info.setHgl(data.get("S1HGL").toString());
        }
        if (data.get("S1M1") != null) {
            sy1Info.setSyzl(data.get("S1M1").toString());
        }
        if (data.get("S1M2") != null) {
            sy1Info.setHghzl(data.get("S1M2").toString());
        }

        // 修改第二个SyInfo
        ConcreteAdmixtureHgl.SyInfo sy2Info = entity.getSy2Info();
        if (sy2Info == null) {
            sy2Info = new ConcreteAdmixtureHgl.SyInfo();
            entity.setSy2Info(sy2Info);
        }
        if (data.get("S2P1") != null) {
            sy2Info.setClp(data.get("S2P1").toString());
        }
        if (data.get("S2HGL") != null) {
            sy2Info.setHgl(data.get("S2HGL").toString());
        }
        if (data.get("S2M1") != null) {
            sy2Info.setSyzl(data.get("S2M1").toString());
        }
        if (data.get("S2M2") != null) {
            sy2Info.setHghzl(data.get("S2M2").toString());
        }
    }
}
